#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <time.h>
#include <unistd.h>
#include <pthread.h>

// typedef std::function<void()> func_t;
using func_t = std::function<void()>;

const int threadnum = 5;
void Print()
{
    std::cout << "我是线程执行的大任务的一部分" << std::endl;
}

// 新线程
void *ThreadRountine(void *args)
{
    size_t num=(size_t)args;
    while (true)
    {
        std::cout<<"i am thread"<<num<<"thread ID"<<pthread_self()<<std::endl;
        sleep(2);
    }
}
int main()
{
    std::vector<pthread_t> pthreads;
    for (size_t i = 0; i < threadnum; i++)
    {
        char threadname[64];
        snprintf(threadname, sizeof(threadname), "%s-%lu", "thread", i);

        pthread_t tid;
        pthread_create(&tid, nullptr, ThreadRountine, (void*)i);
        pthreads.push_back(tid);
        sleep(1);
    }
    std::cout << "thread id: ";
    for(const auto &tid: pthreads)
    {
        std::cout << tid << std::endl;
    }
    std::cout << std::endl;
    while (true)
    {
        std::cout << "main thread" << std::endl;
        sleep(3);
    }
}